package com.coolapk.interceptor;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


@Component
public class UserLoginInterceptor implements HandlerInterceptor {

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        String token = request.getHeader("authorization");
        String sessionToken = (String) request.getSession().getAttribute("token");
//        System.out.println(request.getSession().getId());
        System.out.println("前端token:"+token+"||服务器token:"+sessionToken);
        if (token != "null"){
            if (!StringUtils.isEmpty(sessionToken)){
                if (sessionToken.equals(token)){
                    return true;
                }
                return false;
            }
            return false;
        }
        return false;
    }
}